﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using CMP.ERP.Model;
using CMP.ERP.Helper;
using System.Data.SqlClient;
using System.Configuration;

namespace CMP.ERP.DAL
{
    public  class ProvinceDAL
    {
        /// <summary>
        /// 实例化SQLHelper对象
        /// </summary>
        SQLHelper p = new SQLHelper();

        /// <summary>
        /// 获取省份信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetProvince()
        {
            DataTable dt = p.ExecDataTable("select P_Id,P_Name,P_City from Province");
            return dt;
        }
        //连接数据库字符串
        string connSql = ConfigurationManager.ConnectionStrings["ConnMySql"].ToString();
        //获取省份下拉框(使用Ado五大对象)
        /// <summary>
        /// 获取商品类型
        /// </summary>
        /// <returns></returns>
        public List<Province> GetProvince2()
        {
            string sql = "select P_Id,P_Name,P_City from Province";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connSql);
            DataTable table = new DataTable();
            adapter.Fill(table);
            List<Province> list = new List<Province>();
            foreach (DataRow item in table.Rows)
            {
                Province p = new Province();
                p.P_Id = Convert.ToInt32(item["P_Id"]);
                p.P_Name = item["P_Name"].ToString();
                p.P_City = item["P_City"].ToString();
                list.Add(p);
            }
            return list;
        }
    }
}
